﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:converters="clr-namespace:TTech.IP_Switcher.Converters"
             xmlns:res="clr-namespace:TTech.IP_Switcher.Features.IpSwitcher.Resources"
             xmlns:local="clr-namespace:TTech.IP_Switcher.Features.IpSwitcher"
             xmlns:ddb="clr-namespace:TTech.IP_Switcher.Features.DropDownButton"
             xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d" x:Class="TTech.IP_Switcher.Features.IpSwitcher.IpSwitcherView"
             DataContext="{DynamicResource IpSwitcherViewModel}"
             Focusable="True" d:DesignHeight="348">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../../Styles/Style.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <Style TargetType="{x:Type TextBlock}" BasedOn="{StaticResource defaultTextBlock}">
                <Setter Property="MinWidth" Value="100"/>
            </Style>
            <local:IpSwitcherViewModel x:Key="IpSwitcherViewModel" />
            <converters:BoolToBlurEffectConverter x:Key="BoolToBlurConverter"/>
        </ResourceDictionary>
    </UserControl.Resources>

    <UserControl.InputBindings>
        <KeyBinding Key="F5" Command="{Binding UpdateAdapters}"/>
    </UserControl.InputBindings>

    <Grid x:Name="MainGrid"
          Effect="{Binding Effect, Converter={StaticResource BoolToBlurConverter}}"
          IsEnabled="{Binding IsEnabled}">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Rectangle Grid.Row="1" Margin="10" Grid.ColumnSpan="2" />

        <Grid Grid.Column="0"
              Grid.Row="1"
              Margin="20,20,10,55" >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock Grid.Row="0" TextWrapping="Wrap" Text="{x:Static res:IpSwitcherViewLoc.AdaptersHeader}" VerticalAlignment="Top" Style="{StaticResource Header}"  />
            <ListBox Grid.Row="1"
                     HorizontalAlignment="Stretch"
                     VerticalAlignment="Stretch"
                     ItemsSource="{Binding Adapters}"
                     SelectedItem="{Binding SelectedAdapter}"
                     SelectionMode="Single"
                     FontSize="12"
                     MaxWidth="280"
                     Style="{StaticResource ListBox}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Grid>
                            <StackPanel MaxWidth="230">
                                <TextBlock Text="{Binding Name}"
                                    Foreground="{Binding NetEnabled, Converter={StaticResource BoolToActiveColorConverter}, UpdateSourceTrigger=PropertyChanged}"/>
                                <TextBlock Text="{Binding Description}"
                                    FontSize="10"
                                    Foreground="{Binding NetEnabled, Converter={StaticResource BoolToActiveColorConverter}, UpdateSourceTrigger=PropertyChanged}"/>
                            </StackPanel>
                        </Grid>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Grid>
        <StackPanel Grid.Row="1" Margin="21,21,10,21" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" Orientation="Horizontal" Height="25">
            <Button Content="{x:Static res:IpSwitcherViewLoc.Update}" Command="{Binding UpdateAdapters}" ToolTip="{x:Static res:IpSwitcherViewLoc.UpdateTooltip}"/>

            <ddb:DropDownButton Content="{x:Static res:IpSwitcherViewLoc.Current_Actions}" Margin="5,0,0,0" HorizontalAlignment="Right" VerticalAlignment="Bottom">
                <ddb:DropDownButton.DropDown>
                    <ContextMenu>
                        <MenuItem Header="{x:Static res:IpSwitcherViewLoc.Activate}" Command="{Binding ActivateAdapter}"/>
                        <MenuItem Header="{x:Static res:IpSwitcherViewLoc.Deactivate}" Command="{Binding DeactivateAdapter}"/>
                        <MenuItem Header="{x:Static res:IpSwitcherViewLoc.ShowOnlyPhysical}" IsChecked="{Binding ShowOnlyPhysical}" IsCheckable="True"/>
                    </ContextMenu>
                </ddb:DropDownButton.DropDown>
            </ddb:DropDownButton>
        </StackPanel>

        <TextBlock Grid.Row="1" Text="{x:Static res:IpSwitcherViewLoc.ExternalIp}" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,26"/>
        <TextBlock Grid.Row="1" Text="{Binding ExternalIp}" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="100,0,0,26"/>
        <Button Grid.Row="1" Width="22" Height="16" Grid.Column="1" VerticalAlignment="Bottom" HorizontalAlignment="Right" Margin="0,0,21,26"
                Command="{Binding GetExternalIp}"
                Style="{StaticResource SearchingIpButton}">
            <Path x:Name="Arrow"
                Stretch="Uniform"
                Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}, Mode=FindAncestor}}"
                Data="F1 M 38,20.5833C 42.9908,20.5833 47.4912,22.6825 50.6667,26.046L 50.6667,17.4167L 55.4166,22.1667L 55.4167,34.8333L 42.75,34.8333L 38,30.0833L 46.8512,30.0833C 44.6768,27.6539 41.517,26.125 38,26.125C 31.9785,26.125 27.0037,30.6068 26.2296,36.4167L 20.6543,36.4167C 21.4543,27.5397 28.9148,20.5833 38,20.5833 Z M 38,49.875C 44.0215,49.875 48.9963,45.3932 49.7703,39.5833L 55.3457,39.5833C 54.5457,48.4603 47.0852,55.4167 38,55.4167C 33.0092,55.4167 28.5088,53.3175 25.3333,49.954L 25.3333,58.5833L 20.5833,53.8333L 20.5833,41.1667L 33.25,41.1667L 38,45.9167L 29.1487,45.9167C 31.3231,48.3461 34.483,49.875 38,49.875 Z "/>
        </Button>

        <Grid Grid.Column="1" Grid.Row="1" Margin="0,20,20,55">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition />
            </Grid.RowDefinitions>
            <TextBlock TextWrapping="Wrap" Text="{x:Static res:IpSwitcherViewLoc.CurrentSettings}" VerticalAlignment="Top" Style="{StaticResource Header}"  />
            <ScrollViewer Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Auto">
                <StackPanel>
                    <TextBlock DataContext="{Binding Current}" Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"  Margin="0,0,0,5" VerticalAlignment="Top" />

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_Status}" />
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Status, UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_Speed}" />
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Speed, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_MacAddress}" />
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Mac, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Grid.Row="3" Text="{x:Static res:IpSwitcherViewLoc.Current_DhcpEnabled}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding DhcpEnabled, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_WinsEnabled}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding WinsEnabled, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Grid.Row="5" Text="{x:Static res:IpSwitcherViewLoc.Current_Ip}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Ip, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_DnsServers}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding DnsServers, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_Gateways}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Gateways, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_DhcpServers}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding DhcpServers, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_WinsServers}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding WinsServers, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_AnycastIp}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding AnyCast, UpdateSourceTrigger=PropertyChanged}" />
                    </StackPanel>

                    <StackPanel Orientation="Horizontal">
                        <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_MulticastIp}"/>
                        <TextBlock DataContext="{Binding Current}" Text="{Binding Multicast, UpdateSourceTrigger=PropertyChanged}"/>
                    </StackPanel>

                    <Grid Margin="0,5,0,0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="0.5*"/>
                            <ColumnDefinition Width="0.5*"/>
                        </Grid.ColumnDefinitions>
                        <Button Grid.Column="0" Content="{x:Static res:IpSwitcherViewLoc.Current_ManualSettings}" Command="{Binding ManualSettings}" Margin="0,0,5,0"/>
                        <ddb:DropDownButton Content="{x:Static res:IpSwitcherViewLoc.Current_Actions}" Grid.Column="1">
                            <ddb:DropDownButton.DropDown>
                                <ContextMenu>
                                    <MenuItem Header="{x:Static res:IpSwitcherViewLoc.Current_SaveAsNew}" Command="{Binding ExtractConfigToNewLocation}" />
                                    <MenuItem Header="{x:Static res:IpSwitcherViewLoc.Current_RefreshDhcpLease}" Command="{Binding RefreshDhcpLease}"/>
                                </ContextMenu>
                            </ddb:DropDownButton.DropDown>
                        </ddb:DropDownButton>
                    </Grid>
                </StackPanel>
            </ScrollViewer>
        </Grid>

        <Rectangle Grid.Row="1" Grid.Column="2" Margin="0,10,10,54" />
        <StackPanel Grid.Row="1" Grid.Column="2" Margin="10,20,20,95" >
            <DockPanel>
                <TextBlock Text="{x:Static res:IpSwitcherViewLoc.LocationHeader}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Left"
                    MinWidth="100"
                           Margin="0,0,0,5"
                    DockPanel.Dock="Top"
                    Style="{StaticResource Header}" />
                <ComboBox ItemsSource="{Binding Locations}"
                    SelectedItem="{Binding SelectedLocation}"
                    DisplayMemberPath="Description"
                    HorizontalAlignment="Right"
                    FontSize="14"
                    DockPanel.Dock="Bottom"
                    Width="155"/>
            </DockPanel>
            <StackPanel Orientation="Horizontal" Margin="0,5,0,0">
                <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_DhcpEnabled}" />
                <TextBlock Text="{Binding CurrentLocation.DHCPEnabled}" />
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_Ip}" />
                <TextBlock Text="{Binding CurrentLocation.Ip}" />
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_DnsServers}" />
                <TextBlock Text="{Binding CurrentLocation.Dns}" />
            </StackPanel>

            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{x:Static res:IpSwitcherViewLoc.Current_Gateways}" />
                <TextBlock Text="{Binding CurrentLocation.Gateways}"/>
            </StackPanel>

            <Button Content="{x:Static res:IpSwitcherViewLoc.ApplyLocation}" Command="{Binding ApplyLocation}" Width="155" HorizontalAlignment="Right" Margin="0,5,0,0"/>
            <WrapPanel VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,15,0,0">
                <Button Content="{x:Static res:IpSwitcherViewLoc.EditLocation}" Width="75" Margin="0,0,5,0" Command="{Binding EditLocation}" />
                <Button Content="{x:Static res:IpSwitcherViewLoc.DeleteLocation}" Width="75" Command="{Binding DeleteLocation}" />
            </WrapPanel>
            <Button Content="{x:Static res:IpSwitcherViewLoc.CreateLocation}" Width="155" HorizontalAlignment="Right" Margin="0,5,0,0" Command="{Binding CreateLocation}" />
        </StackPanel>

        <Rectangle Grid.Row="1" Grid.Column="2"  Margin="0,10,10,10" Height="38" VerticalAlignment="Bottom" RadiusX="0"/>
        <TextBlock Grid.Row="1" Grid.Column="2"  Margin="11,0,21,26" Text="{Binding StatusText}" Height="16" VerticalAlignment="Bottom" HorizontalAlignment="Stretch" />
        <ProgressBar Grid.Row="1" Grid.Column="2"
                     Margin="11,0,21,16"
                     Height="8"
                     VerticalAlignment="Bottom"
                     HorizontalAlignment="Stretch" Width="Auto" IsIndeterminate="{Binding IsWorking}" />

        <ddb:DropDownButton Grid.Row="1" Content="{x:Static res:IpSwitcherViewLoc.Current_Actions}" Grid.Column="2" Height="16" Margin="0,0,20,64" Width="73" HorizontalAlignment="Right" VerticalAlignment="Bottom">
            <ddb:DropDownButton.DropDown>
                <ContextMenu>
                    <MenuItem Header="{x:Static res:IpSwitcherViewLoc.ImportPresets}" Command="{Binding ImportPresets}"/>
                    <MenuItem Header="{x:Static res:IpSwitcherViewLoc.ExportPresets}" Command="{Binding ExportPresets}"/>
                </ContextMenu>
            </ddb:DropDownButton.DropDown>
        </ddb:DropDownButton>
    </Grid>
</UserControl>
